<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>脚本管理</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	$.canEdit = true;
	$.canView = true;
</script>
<script type="text/javascript">
	var dataGrid;
	var editRow = undefined;
	var versionComboboxFromScript;
	var productComboboxFromScript;
	
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${pageContext.request.contextPath}/scriptController/dataGrid',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 20,
			pageList : [ 20, 50, 100, 200 ],
			sortName : 'totalFailNum',
			sortOrder : 'desc',
			checkOnSelect : true,
			selectOnCheck : true,
			nowrap : false,
			striped : true,
			rownumbers : true,
			//singleSelect : true,
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 150,
				//hidden : true,
				checkbox : true
			}, {
				field : 'name',
				title : '脚本名称',
				width : 200
			}, {
				field : 'testcaseNumber',
				title : '用例number',
				width : 500
			}] ],
			columns : [ [{
				field : 'totalFailNum',
				title : '失败的次数',
				width : 150,
				sortable : true
			}, {
				field : 'versionName',
				title : '版本号',
				width : 200
			}, {
				field : 'solveType',
				title : '解决状态',
				width : 200
			}, {
				field : 'action',
				title : '操作',
				width : 200,
				formatter : function(value, row, index) {
					var str = '';
					if ($.canEdit) {
						str += $.formatString('<img onclick="editFun(\'{0}\');" src="{1}" title="编辑"/>', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png');
					}
					str += '&nbsp;';
					str += '&nbsp;';
					str += '&nbsp;';
					str += '&nbsp;';
					str += '&nbsp;';
					str += '&nbsp;';
					if ($.canView) {
						str += $.formatString('<img onclick="viewFun(\'{0}\');" src="{1}" title="查看"/>', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/zoom/zoom.png');
					}
					return str;
				}
			}] ],
			
			onLoadSuccess : function() {
				$('#searchFormByScript table').show();
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			}
			
		});
		
		// 增加回车搜索的功能,千万不能调keyup
		$('#searchFormDivByScript input').keypress(function(event) {
			if (event.keyCode == '13') {
				searchFunByScript();
				return false;
			}
		});
		
		// 根据产品关联查询出版本号
		productComboboxFromScript = $('#script_form_product').combobox({
			url : '${pageContext.request.contextPath}/productController/productCombobox',
			valueField : 'name',
			textField : 'name',
			required : true,
			panelHeight : 'auto',
			mode : 'remote',
			delay : 500,
			onSelect: function(rec){
			    var url = '${pageContext.request.contextPath}/versionController/versionCombobox?productName='+rec.name;
			    $('#script_form_version').combobox('reload', url);
		    }
		});
		
		
		versionComboboxFromScript = $('#script_form_version').combobox({
			valueField:'name',
			textField:'name',
			required : true
		});
		
		
		
	});
	
	function editFun(id) {
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		}
		parent.$.modalDialog({
			title : '编辑',
			width : 1000,
			height : 650,
			href : '${pageContext.request.contextPath}/scriptController/editPage?id=' + id,
			buttons : [ {
				text : '编辑',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}

	function viewFun(id) {
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		}
		parent.$.modalDialog({
			title : '查看',
			width : 1000,
			height : 650,
			href : '${pageContext.request.contextPath}/scriptController/view?id=' + id
		});
	}
	
	function searchFunByScript() {
		dataGrid.datagrid('load', $.serializeObject($('#searchFormByScript')));
	}
	
	function cleanFunByScript() {
		$('#searchFormByScript input').val('');
		dataGrid.datagrid('load', {});
	}

</script>
</head>
<body>
	<div id="searchFormDivByScript" class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 100px; overflow: hidden;">
				<form id="searchFormByScript">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<td>产品 ： </td>
						<td><input id="script_form_product" name="productname" ></td>
						<th>版本号：</th>
						<td><input id="script_form_version" name="versionName"/></td>
						<th>用例ID：</th>
						<td><input name="testcaseNumber" placeholder="请输入用例ID" class="span3" /></td>
						
						<td><a href="#"  onclick="searchFunByScript()" class="btn btn-primary span1">搜索</a></td>
						<td><a href="#"  onclick="cleanFunByScript()" class="btn btn-primary span1">清除</a></td>
					</tr>
					<tr>
						<th></th>
						<td colspan="3"></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
</body>
</html>